package org.pp.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.pp.admin.dto.PpCategorizeAdd;
import org.pp.admin.dto.PpCategorizeEdite;
import org.pp.admin.dto.PpCategorizePage;
import org.pp.annotations.Permission;
import org.pp.core.PageBean;
import org.pp.core.Result;
import org.pp.dto.PageDto;
import org.pp.entity.PpCategorize;
import org.pp.store.OssStore;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品类别 前端控制器
 * </p>
 *
 * @author haima
 */
@RestController
@RequestMapping("/categorize")
public class PpCategorizeController
extends BaseCrudController<PpCategorize, PpCategorizeAdd, PpCategorizeEdite,PpCategorize>
    implements  BaseAdd<PpCategorizeAdd>,
        BaseEdite<PpCategorizeEdite>,
        BaseDelete,
        BasePage<PpCategorize>
{
    @Autowired
    OssStore ossStore;

    @Override
    @Permission("post:/categorize/add")
    public Result<Object> add(PpCategorizeAdd dto) {
        return super.add(dto);
    }

    @Override
    @Permission("post:/categorize/edite")
    public Result<Void> edite(PpCategorizeEdite dto) {
        return super.edite(dto);
    }

    @Override
    @Permission("post:/categorize/delete")
    public Result<Void> delete(String ids) {
        return super.delete(ids);
    }


    @GetMapping("/list")
    @Permission("get:/categorize/delete")
    @Operation(summary = "CRUD操作 分页查询")
    public Result<PageBean<PpCategorize>> page(@ParameterObject PpCategorizePage page) {
        Result<PageBean<PpCategorize>> res = super.page(page);
        res.getData().getList().forEach(
                e->{
                    e.setIcoUrl(ossStore.getUrl(e.getIco()));
                }
        );
        return res;
    }
}
